#ifndef _IMAGE_FILM_H_
#define _IMAGE_FILM_H_
#include <unordered_set>

#include "film.h"
#include "display.h"

class MitchellFilter;

class ImageFilm:public Film
{
public:
	ImageFilm(unsigned w,unsigned h, unsigned int wr);
	void WriteImage(unsigned progressive_iteration);//update the back color buffer for every progressive_iteration
	void AddSample(const camera_sample_t& cam_samp,const spectrum_t& c);
	void ClearSamples();
	unsigned GetWidth()const;
	unsigned GetHeight()const;
	virtual void GetUpdateBuffer(unsigned progressive_iteration, std::vector<spectrum_t>* color_buffer) const;
	~ImageFilm();
protected:
private:
	unsigned int write_frequency_;//todo: change to be update_frequency
	unsigned int current_iteration_;
	unsigned int current_sample_count_;
	unsigned width_,height_;
	struct Pixel{
		Pixel(){
			weight_sum = 0;
		}
		spectrum_t l;
		float weight_sum;
	};
	Pixel *color_back_;
	float *color_buffer_;//the acummulated color buffer

	MitchellFilter* filter_;
	float *precomputed_filter_table_;
	Display* image_display_;



struct hash_camera_sample_t{
	size_t operator()(const camera_sample_t& s)const
	{
		typedef std::hash<float> float_hash_function_t;
		float_hash_function_t fh;
		size_t seed = fh(s.image_x);
		return fh(s.image_y) + 0x9e3779b9 + (seed<<6) + (seed>>2);
	}
};
	std::unordered_set<camera_sample_t,hash_camera_sample_t> current_samples_;
};


#endif